package com.xujiakai.car.maintain.domain.entity;

import com.xujiakai.car.maintain.application.service.impl.BaseDataManageService;
import com.xujiakai.car.maintain.infrastructure.mapper.DaoFactory;
import com.xujiakai.car.maintain.infrastructure.utils.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class Part {
    private Integer id;

    private String partnumbering;

    private Integer partcategoryid;

    private String partname;

    private Double purchaseprice;

    private Double salesprice;

    private String specifications;

    private String remarks;

    private String partflag;

    private Integer supplierid;

    @Resource
    private DaoFactory daoFactory;

    private com.xujiakai.car.maintain.domain.dto.PartDTO part;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getPartnumbering() {
        return partnumbering;
    }

    public void setPartnumbering(String partnumbering) {
        this.partnumbering = partnumbering == null ? null : partnumbering.trim();
    }

    public Integer getPartcategoryid() {
        return partcategoryid;
    }

    public void setPartcategoryid(Integer partcategoryid) {
        this.partcategoryid = partcategoryid;
    }

    public String getPartname() {
        return partname;
    }

    public void setPartname(String partname) {
        this.partname = partname == null ? null : partname.trim();
    }

    public Double getPurchaseprice() {
        return purchaseprice;
    }

    public void setPurchaseprice(Double purchaseprice) {
        this.purchaseprice = purchaseprice;
    }

    public Double getSalesprice() {
        return salesprice;
    }

    public void setSalesprice(Double salesprice) {
        this.salesprice = salesprice;
    }

    public String getSpecifications() {
        return specifications;
    }

    public void setSpecifications(String specifications) {
        this.specifications = specifications == null ? null : specifications.trim();
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks == null ? null : remarks.trim();
    }

    public String getPartflag() {
        return partflag;
    }

    public void setPartflag(String partflag) {
        this.partflag = partflag == null ? null : partflag.trim();
    }

    public Integer getSupplierid() {
        return supplierid;
    }

    public void setSupplierid(Integer supplierid) {
        this.supplierid = supplierid;
    }

    public boolean delPart(String partid) {
        boolean flag = false;
        try {
            // 查询
            com.xujiakai.car.maintain.domain.dto.PartDTO part = daoFactory.getPartMapper().selectByPrimaryKey(Integer.valueOf(partid));
            if (part != null) {
                part.setPartflag("0");
                // 更新数据库
                daoFactory.getPartMapper().updateByPrimaryKeySelective(part);
                flag = true;
            }
        } catch (Exception e) {
            BaseDataManageService.logger.info("删除零件信息异常!");
        }
        return flag;
    }

    public com.xujiakai.car.maintain.domain.dto.PartDTO getPart(String partid){
        part = daoFactory.getPartMapper().selectByPrimaryKey(StringUtils.getIntegerValue(partid, -1));
        return part;
    }

    public int setPrice(double price){
        part.setPurchaseprice(price);
        return daoFactory.getPartMapper().updateByPrimaryKeySelective(part);
    }

    public boolean modifyPrice(Integer partid, double price) {
        boolean flag = false;
        com.xujiakai.car.maintain.domain.dto.PartDTO part = daoFactory.getPartMapper().selectByPrimaryKey(partid);
        if(part!=null){
            part.setSalesprice(price);
            flag = daoFactory.getPartMapper().updateByPrimaryKeySelective(part)>0;
        }
        return flag;
    }
}